﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Lab1
{
    public class CriterionService
    {
        private DatabaseEntities db = new DatabaseEntities();
        public IEnumerable<Criterion> getAll()
        {
            List<Criterion> list= (from t in db.Criterian
                    select t).ToList();
  
            return list;
        }
        public void update(Criterion model)
        {

            using (DatabaseEntities context = new DatabaseEntities())
            {
                var original = (from t in context.Criterian
                                where t.Id.Equals(model.Id)
                                select t).SingleOrDefault();
                context.Criterian.ApplyCurrentValues(model);
                context.SaveChanges();
            }

        }
        public void delete(Criterion model)
        {
            using (DatabaseEntities context = new DatabaseEntities())
            {
                var original = (from t in context.Criterian
                                where t.Id.Equals(model.Id)
                                select t).SingleOrDefault();
                context.DeleteObject(original);
                context.SaveChanges();
            }
        }
        public void save(Criterion model)
        {
            db.AddToCriterian(model);
            db.SaveChanges();
        }

        public Criterion getById(Guid id)
        {
            Criterion model= (from t in db.Criterian
                    where t.Id.Equals(id)
                    select t).Single<Criterion>();
      
            return model;
        }
    }
}
